package com.dfbz.service.impl;

import com.dfbz.constant.Const;
import com.dfbz.service.FileSerivce;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;

@Service
public class FileServiceImpl implements FileSerivce {


    @Override
    public String setUploadPic(MultipartFile uploadPic) {

        String filename = uploadPic.getOriginalFilename();

        File file =new File(Const.PATH);

        if (!file.exists()){
            file.mkdirs();
        }

        String newFileAndPath = Const.PATH + filename;
        try {
            uploadPic.transferTo(new File(newFileAndPath));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return filename;
    }

}
